home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10999 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.6 KB  |  85 lines

  1. Newsgroups: comp.lang.c++
  2. Path: news.sprintlink.net!mv!bnb
  3. From: bnb@curtech.com (Brian Ballard)
  4. Subject: Creating operator= for *pointers* to objects??
  5. Message-ID: <Do4KtH.MK@mv.mv.com>
  6. Organization: Current Technology
  7. Date: Mon, 11 Mar 1996 22:51:17 GMT
  8. X-Newsreader: TIN [version 1.2 PL2]
  9. X-Nntp-Posting-Host: artichoke.curtech.com
  10.  
  11.  
  12.  
  13. I'm trying to find a way to create an assignment (or copy) operator
  14. which I can use to apply to pointers to object.  For example, say I have
  15. a class hierarchy that looks like:
  16.  
  17.          |--- B
  18.     A ---|--- C
  19.          |--- D
  20.  
  21. Millions of these objects can potentially be created and scrapped every
  22. few minutes so, in order to improve performance and reduce memory
  23. fragmentation, every class in the hierarchy has their new/delete operators
  24. overloaded to use a handful of "pre-built" objects in the freestore.
  25. Pretty standard stuff.
  26.  
  27. Because exact duplicates of an instantiated object can (and must) exist,
  28. class A has a refCount member which allows me to keep track of how many
  29. copies of a duplicated object exist out there, so I don't pull the rug
  30. out from under an object that is still being used.
  31.  
  32. In general, megabytes worth of network packets are stored in a file, which
  33. get read in by this software and are wrapped up in one of the above derived
  34. classes (B, C, or D) depending upon the type of packet.  This creates a
  35. virtual "list" of sorts where I have an iterator which walks through the
  36. file, returning objects of type B/C/D.
  37.  
  38. Basically, I'd like to be able to do this:
  39.  
  40. {
  41.  A*    start = NULL;
  42.  A*    temp = NULL;
  43.  
  44.  start = mStream->GetPacketAtOffset(0L);    // This might return an object B*
  45.  temp = start;                              // I need this to call my oper=
  46.  while ( temp = mStream->GetNextPacket(temp)) // GetNextPacket automatically
  47.     bla bla bla                               // 'delete's first A* temp
  48.  
  49. ...
  50.  
  51. In the above example, I need "temp = start" to "delete temp", create a
  52. duplicate of "start" and return its pointer into "temp"
  53.  
  54. Right now, I have to do this:
  55.  
  56. {
  57. ...
  58.    delete temp;
  59.    temp = start->Copy();
  60. ...
  61. }
  62.  
  63. Not a big deal to it this way, but it's easy to forget over the long haul
  64. that these steps need to be taken.  It's much easier to do a simple pointer
  65. assignment which guarantees that every pointer to an object is accounted for.
  66.  
  67.  
  68. OK.... a bit much content for such an easy question....
  69.  
  70. thanx,
  71. brian
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. --
  80. Brian Ballard                          |
  81. Current Technology, Inc.               |    "the ultimate development
  82. Durham, New Hamsphire                  |           of total harmony....."
  83. bnb@curtech.com                        |
  84.